
/**
 **************************************************************************************************************************
 * Class representing a bounding volume
 **************************************************************************************************************************
 * @file RBBVolume.h
 **************************************************************************************************************************/


#ifndef __RBBVOLUME_H__
#define __RBBVOLUME_H__


/**************************************************************************************************************************
 * Includes
 **************************************************************************************************************************/
#include "RBTSpatialComponent.h"
#include "RBHandle.h"
#include "RBVector.h"

/**************************************************************************************************************************
 * Forward declarations
 **************************************************************************************************************************/
class RBStream;

/**************************************************************************************************************************
 * Classes
 **************************************************************************************************************************/

RBDeclareHandle(RBBVolume);
typedef std::vector<RBBVolumeHandle> RBBVolumeArray;

class RBBVolume : public RBTSpatialComponent<RBBVolume>
{
public:
    RB_DECLARE_COMPONENT(RBBVolume);

                        RBBVolume       (RBEntityHandle entityHandle, RBTransformComponentHandle xForm);
    virtual            ~RBBVolume       ();

    void                ComputeFromData (const float* pPoints, uint32 uiPoints);

    void                Update           (const RBTransform& worldXForm);

    void                SetObject        (uint16 classIdx, uint16 object) { m_componentType = classIdx; m_handle = object; }

    template<class TComponent>
    void                SetObject        (RBHandle<TComponent> object) { m_componentType = TComponent::GetClassIdx(); m_handle = object.Handle; }

    template<class TComponent>
    RBHandle<TComponent> GetObject() { RBAssert(m_componentType == TComponent::GetClassIdx(), "Wrong object Type !"); return m_handle; }

    inline uint16       GetObjectType() const { return m_componentType; }
    inline uint16       GetObjectHandle() const { return m_handle; }

    static void         UpdateEntity(RBEntityHandle handle);
    
    void                copy_members        (RBBVolumeHandle dest);

    float3              ModelCenter;
    float3              ModelExtents;

    float3              Axes[3];
    float               Extents[3];
    float3              Center;

private:
    uint16 m_componentType;
    uint16 m_handle;

};

#include "RBBVolume.inl"

/**************************************************************************************************************************/

#endif // __RBBVOLUME_H__
